//
//  ZYmainTaBar.swift
//  ZYweibo
//
//  Created by apple on 15/12/20.
//  Copyright © 2015年 zhuyipeng. All rights reserved.
//

import UIKit

class ZYmainTaBar: UITabBar {

    private let count = 5
    override func layoutSubviews() {
        super.layoutSubviews()
        let width = self.bounds.width / CGFloat(count)
        let frame = CGRect(x: 0, y: 0, width: width, height: self.bounds.height)
        var index = 0
        for view in self.subviews{
            // 设置 UITabBarButton 的frame
            // UITabBarButton 继承UIContorl
            // is: 判断类型
            if view is UIControl && !(view is UIButton) {
                view.frame = CGRectOffset(frame, width * CGFloat(index), 0)
                index += index == 1 ? 2 : 1
            }
            
            
        }
//
        composeButton.frame = CGRectOffset(frame, width * 2.0, 0)
    }
//
    lazy var composeButton : UIButton = {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        return button
    }()
}
